package com.party.web.web.dto.output.wechat;

import com.alibaba.fastjson.JSON;
import com.party.core.model.wechat.WechatMessage;
import com.party.web.web.dto.input.wechat.KeyValue;
import org.apache.commons.beanutils.BeanUtils;

import java.lang.reflect.InvocationTargetException;

/**
 * Created by admin on 2017/8/29.
 */
public class KeywordResponseOutput {

    private String id;
    private Integer type;
    private String key;
    private String content;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public static KeywordResponseOutput transform(WechatMessage wechatMessage){
        KeywordResponseOutput output = new KeywordResponseOutput();
        KeyValue keyValue = JSON.parseObject(wechatMessage.getContent(),KeyValue.class);
        try {
            BeanUtils.copyProperties(output,wechatMessage);
            output.setKey(keyValue.getKey());
            output.setContent(keyValue.getValue());
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        return output;
    }
}
